package ar.com.solidussource.framework.backend.dao.filter;

import org.hibernate.Criteria;
import org.hibernate.criterion.Order;

public abstract class OrderedFilter implements Filter{

	private TableOrder tableOrder;

	public TableOrder getTableOrder() {
		return tableOrder;
	}

	public void setTableOrder(TableOrder tableOrder) {
		this.tableOrder = tableOrder;
	}
	
	public void fillCriteria(Criteria criteria){
		
		if(tableOrder.getDirection().equals("asc")){
			criteria.addOrder(Order.asc(tableOrder.getCriterion()));
		}
		else{
			if(tableOrder.getDirection().equals("desc")){
				criteria.addOrder(Order.desc(tableOrder.getCriterion()));
			}
		}
		
		this.fillCriteriaNoOrder(criteria);
		
	}
	
	abstract public void fillCriteriaNoOrder(Criteria criteria);
	
	
}
